package com.mzy.linear_struct.hot100.滑动窗口;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: mizy3
 * @Date: 2024/07/04/上午9:14
 * @Description:
 */
public class Pro03无重复字符的最长子串 {
    public static int lengthOfLongestSubstring(String s) {
        if (s.length() == 1) return 1;
        //  s
        // abcabcbb
        //    e
        Map<Character, Integer> map = new HashMap<>();
        int ans = 0;
        int start = 0, end = 0;

        while (end < s.length()) {
            char c = s.charAt(end);

            if(map.containsKey(c)){
                start = Math.max(start, map.get(c) + 1);
            }
            map.put(c, end);
            ans = Math.max(end - start + 1, ans);

            end++;
        }

        return ans;
    }

    public static void main(String[] args) {
        System.out.println(lengthOfLongestSubstring("pwwkew"));
    }























}
